import Base from "../base.js";
import cinemaService from "../../service/cinemaService.js";
export default class extends Base {
  constructor(props) {
    super(props);

  }
  render() {
    const template = `
    <form class="layui-form" action="" style="width:400px">
    <div class="layui-form-item">
      <label class="layui-form-label">影院名</label>
      <div class="layui-input-inline">
        <input type="text" required name="name" lay-verify="required" placeholder="请输入影院名" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">影院地址</label>
      <div class="layui-input-inline">
        <input type="text" name="address" required lay-verify="required" placeholder="请输入地址" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">影院电话</label>
      <div class="layui-input-inline">
        <input type="text" name="phone" required lay-verify="required"  placeholder="请输入影院电话" autocomplete="off" class="layui-input" max-length=6>
      </div>
    </div>
    <div class="layui-form-item">
    <label class="layui-form-label">是否营业</label>
    <div class="layui-input-block">
      <input type="radio" name="status" value="true" title="是" checked>
      <input type="radio" name="status" value="false" title="否">
    </div>
  </div>
    <div class="layui-form-item">
      <div class="layui-input-block">
        <button type="button" class="layui-btn createBtn" lay-submit lay-filter="formDemo">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
      </div>
    </div>
  </form>
        `
    this.$el.html(template);
  }

  async create(cinemas) {
    let data = await cinemaService.create(cinemas);
  }

  handle() {
    // let cinema = { cinemas: "", address: "", phone: "", };
    // for (let key in cinema) {
    //   $(`input[name=${key}]`).on("input", function () {
    //     cinema[key] = $(this).val();
    //   })
    // };
    this.form.on('submit(formDemo)', async (cinemas) => {
      const Boolear =cinemas.field;
      if (Boolear == "true") {
        Boolear = true;
      }
      if (Boolear == "false") {
        Boolear = false;
      }
      await this.create(Boolear);
      location.hash = "#/info/cinemaList";
      return false;
    });
  }
  layui() {
    this.form.render();
  }
}